package com.pan.admin.module.visualizer.service.impl;

import com.pan.admin.module.visualizer.dao.LoanProductVisualizerDao;
import com.pan.admin.module.visualizer.entity.po.LoanProductVisualizerPO;
import com.pan.admin.module.visualizer.entity.qo.LoanProductVisualizerQO;
import com.pan.admin.module.visualizer.service.LoanProductVisualizerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Service
public class LoanProductVisualizerServiceImpl implements LoanProductVisualizerService {

    @Autowired
    private LoanProductVisualizerDao loanProductVisualizerDao;

    @Override
    @Transactional(readOnly = true)
    public List<LoanProductVisualizerPO> listLoanProductProduct(LoanProductVisualizerQO loanProductVisualizerQO) {
        //  机构信息
        List<LoanProductVisualizerPO> loanProductList = this.loanProductVisualizerDao.listLoanProduct(loanProductVisualizerQO);
        //  撞库状态信息
        List<LoanProductVisualizerPO> loanProductApplyFlowList = this.loanProductVisualizerDao.listLoanProductApplyFlow(loanProductVisualizerQO);
        //  最终的撞库信息
        List<LoanProductVisualizerPO> list = new ArrayList<>();
        //  循环机构信息
        loanProductList.forEach(loanProduct -> {
            //  循环撞库状态信息
            loanProductApplyFlowList.forEach(loanProductApplyFlow -> {
                if (loanProductApplyFlow.getLoanProductId().equals(loanProduct.getLoanProductId())) {
                    LoanProductVisualizerPO data = new LoanProductVisualizerPO();
                    data.setLoanProductId(loanProductApplyFlow.getLoanProductId());
                    data.setLoanProductName(loanProduct.getLoanProductName());
                    data.setStatus(loanProductApplyFlow.getStatus());
                    data.setTotal(loanProductApplyFlow.getTotal());
                    list.add(data);
                }
            });
        });
        return list;
    }
}
